home *** CD-ROM | disk | FTP | other *** search
INI File | 2001-09-10 | 2.5 KB | 67 lines |
- [Name]
- KeyBoardEvent v1.0 - provides framework for keypress events
- By Matthew Peterson, matthew@pinoko.berkeley.edu
-
- [Description]
- 2-29-2000
- Currently Quicktime doesn't have much of an interface for text
- or keyboard interaction. All one can do is test if a specific key
- is currently being pressed. Thus in order to check which key is
- pressed, it is necessary to check each and every key in a loop.
- This sounds bad, but it turns out that for most machines, we
- can get away with it. I've done a couple of things to help speed
- this process up. For example, I've made separate behaviors for
- different sets of characters. Just add the ones you want to
- check (letters, numbers, control...) as an addition to this
- behavior.
-
- To use, place this behavior in a sprite, and pick a set of
- characters to poll by placing one or more of the accompanying
- accessory behaviors on the same sprite. In the parameters,
- set the ID of the event you would like to have executed once
- a key is pressed.
-
- You can now place QScript code in your specified custom event
- to handle keyboard events. The following Global Variables should
- be used to help in this process:
-
- Global Variables:
- 1) KeyBoardOn -- Set to true to poll the keyboard.
- 2) WhichKeyN -- The ascii number of the key pressed. You may
- use the accompanying asciiArray behavior to give
- your scripts access to the ascii table. But in general
- it is sufficient to know that 48='0'and 65='A'.
- 3) oldKeyN -- The previous value of WhichKeyN. It is often useful to
- check if oldKeyN = WhichKeyN.
- 4) IsCap -- When using the LetterKeys, IsCap will tell you if the letter
- pressed is a capital letter or not.
-
- Revision History:
- 2-19-2000 : wrote it
- 2-29-2000: made it faster by placing all the key polling in the same event.
-
- [Parameters]
-
- On KeyPress Event ID:, MP_KBCustomEventID,79
-
- [Idle]
- GlobalVars KeyBoardOn
- IF(KeyBoardOn)
- ExecuteEvent(200079)
- ENDIF
-
- [200079 MP_KeyboardEvent]
- GlobalVars whichkeyN oldkeyN IsCap
- //This is a simple polling structure. It executes events
- //That check if keys are being pressed, then if there is a
- //change in the current keypressed status, it executes the
- //custom event defined by the user.
- whichkeyN = -1 //cleared state
- ExecuteEvent(200072) //Poll the keys.
-
- IF(whichkeyN ≠ oldkeyN AND whichkeyN > 0)//If new key
- isCap = KeyIsDown(kShiftKey,"") OR KeyIsDown(kCapsLockKey,"") AND NOT KeyIsDown(kShiftKey | kCapsLockKey,"")
- ExecuteEvent($MP_KBCustomEventID)
- ENDIF
-
- oldkeyN = whichKeyN //remember this key for next idle event.